﻿
namespace WindowsAPI.Hardware
{
    public static class HardwareExtentions
    {
        //public static IntPtr RegisterForUsbEvents(IntPtr hWnd, Guid gClass)
        //{
        //    var oInterfaceIn = new DevBroadcastDeviceInterfaceBuffer();
        //    oInterfaceIn.Size = Marshal.SizeOf(oInterfaceIn);
        //    //oInterfaceIn.ClassGuid = gClass;
        //    oInterfaceIn.DeviceType = DEVTYP_DEVICEINTERFACE;// DEVTYP_DEVICEINTERFACE = 0x05;
        //    oInterfaceIn.Reserved = 0;
        //    return User32.RegisterDeviceNotification(hWnd, oInterfaceIn, DEVICE_NOTIFY_WINDOW_HANDLE);// DEVICE_NOTIFY_WINDOW_HANDLE = 0;
        //}

        //public static string Eject(bool allowUI)
        //{
        //    var USBData = SP_DEVINFO_DATA.Default;
        //    if(!allowUI)
        //    {

        //        SetupAPI.CM_Request_Device_Eject_NoUi(USBData.DevInst, IntPtr.Zero, null, 0, 0); // USBData, a SP_DEVINFO_DATA structure.
        //    }
        //    else
        //    {
        //        var sb = new StringBuilder(1024);

        //        PNP_VETO_TYPE veto; // PNP_VETO_TYPE enumeration is used to identify the reason for rejection
        //        var hr = SetupAPI.CM_Request_Device_Eject(USBData.DevInst, out veto, sb, sb.Capacity, 0);

        //        if(hr != 0)
        //            throw new Win32Exception(hr);
        //        if(veto != PNP_VETO_TYPE.Ok)
        //            return veto.ToString();
        //    }
        //    return null;
        //}
    }
}
